package cn.heygod.nacostool.web;

import cn.heygod.nacostool.config.NacosConfig;
import cn.heygod.nacostool.config.DeployConfig;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Simon
 */
@Controller
@RequestMapping("/api/service")
public class ServiceController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private NacosConfig nacosConfig;


    @Autowired
    private DeployConfig deployConfig;


    @RequestMapping("/info")
    @ResponseBody
    public Object info(){
        Map<String,String> map = new HashMap<>();
        map.put("serverAddr",nacosConfig.getServerAddr());
        map.put("group",nacosConfig.getGroup());
        map.put("env",deployConfig.getEnv());
        map.put("services", StrUtil.join(StrUtil.COMMA, deployConfig.getServices()) );
        return map;
    }


}
